﻿/*
*   学员信息页面
*/
angular.module('jisuStuHome')
.controller('stuQueInfo', ['$rootScope', '$scope', '$state', '$interval', 'StuRequestTrain', 'sysUserInfo', 'Msg', 'T', 'LS', function ($scope, $rootScope, $state, $interval, ST, sysUserInfo, Msg, T, LS) {
    console.log($scope.timer);
    if ($scope.timer)
        $interval.cancel($scope.timer);
    // 打开错题列表，收藏列表
    $scope.playOpenList = function (id) {
        //knowledgeId:知识架构id
        //console.log(id);
        $state.go('home.knowledgestructurelist', { knowledgeId: $stateParams.knowledgeId, typeId: id });
    }
    // 返回知识分类  index  条数  在本地
    var $stateParams = LS.getLS(sysUserInfo.getuserinfo().user_ID + '_stuQueInfo');
    console.log("头部信息" + $stateParams.userQuestionsInfo, "索引" + $stateParams.groupIndex, "条数" + $stateParams.groupPath, "类型" + $stateParams.stuQueList.xid, "合格类型空和0表示全部答完" + $stateParams.stuQueList.passtype, "合格数值" + $stateParams.stuQueList.pass, "错题、收藏、顺序" + $stateParams.stuQueList.typeId, "智能抽题参数" + $stateParams.smartQueParams, "父级分类Id" + $stateParams.stuQueList.parentId + "父级知识分类" + $stateParams.stuQueList.parentName);
    // 判空
    $scope.isNull = function (text) {
        if (text == undefined || text == null || text == "" || text.length <= 0) {
            return true;
        } else {
            return false;
        }
    }


    // 是否显示头手机或者课程
    if ($scope.isNull($stateParams.stuQueList.userId)) {
        $rootScope.headerShow = true;
    } else {
        $rootScope.headerShow = false;
        if (document.getElementById("kefu"))
            document.getElementById("kefu").remove();
        if (document.getElementById("topbar"))
            document.getElementById("topbar").remove();
    }
    // 类型id 重新赋值一下
    $stateParams.xid = $stateParams.stuQueList.xid;
    $scope.init = function () {
        // 判断参数为空 回到任务列表
        if ($scope.isNull($stateParams) || $scope.isNull($stateParams.userQuestionsInfo) || $scope.isNull($stateParams.userQuestionsInfo.knowledge.knowledge_Id)) {  // 判断参数是否存在
            Msg.info('提示', '参数有误请您重新传入');
            $state.go('home.trainlist');
        }
        // 类型 0 练习 1 错误  2 收藏
        $scope.typeId = $scope.isNull($stateParams.stuQueList.typeId) ? 0 : $stateParams.stuQueList.typeId;
        // 选项
        $scope.redioList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
        // 答题难度
        $scope.difficultyList = ['', '简单', '一般', '困难'];
        // 传入的参数
        $scope.userQuestionsInfo = $stateParams.userQuestionsInfo;
        // 判断是否开启下题返回再答题 false不可以用 true 可以返回再答题        
        //$scope.userQuestionsInfo.isOpen = false;
        // 配合开关控制题目是否可答默认必须答一次
        $scope.questionsIsOpen = true;
        // 计算正确率
        if (!$scope.isNull($scope.userQuestionsInfo.alltotleCount) && $scope.userQuestionsInfo.alltotleCount != 0) {
            $scope.userQuestionsInfo.correctRate = parseInt(($scope.userQuestionsInfo.allcorrotCount / $scope.userQuestionsInfo.alltotleCount) * 100);
        } else {
            $scope.userQuestionsInfo.correctRate = 0;
        }

        // 计算题目正确率
        if (!$scope.isNull($scope.userQuestionsInfo.totleQuestion) && $scope.userQuestionsInfo.totleQuestion != 0) {
            $scope.userQuestionsInfo.allcorrectRate = parseInt(($scope.userQuestionsInfo.allcorrotQuestionCount / $scope.userQuestionsInfo.totleQuestion) * 100);
        } else {
            $scope.userQuestionsInfo.allcorrectRate = 0;
        }
        // 当前题目开始数
        $scope.startQuestionsNum = (($stateParams.groupIndex - 1) * $stateParams.groupPath);
        // 当前截止题目数
        if (($stateParams.groupIndex * $stateParams.groupPath) > $scope.userQuestionsInfo.totleQuestion) { //如果超过了最大的题目
            $scope.endQuestionsNum = $scope.userQuestionsInfo.totleQuestion;
        } else {
            $scope.endQuestionsNum = $stateParams.groupIndex * $stateParams.groupPath;
        }
        // 已答题目数
        $scope.haveQuestionsNum = [];
        // 已答题的集合
        $scope.haveQuestionsList = [];
        // 总时长(秒)
        $scope.countTime = parseInt($scope.isNull($stateParams.userQuestionsInfo.totleTime) ? 0 : $stateParams.userQuestionsInfo.totleTime);
        // 当前时长
        $scope.currentTime = 0;
        // 单道题目的时长
        $scope.currentQueTime = 0;
        // 组正确率
        $scope.correctQue = 0;
        // 计时器开关
        $scope.timerFlag = true;
        //  计时器
        $scope.timer = null;
        // 创建计时器
        $scope.timerFun();
        // 题目列表 
        $scope.queList = [];
        // 当前题目索引
        $scope.queObj = "";

        // 提交练习数据
        $scope.queDataParams = {
            questionJSON: [],   // 答题的题目
            groupRecord: $stateParams.groupIndex,   // 组
            answerCostTime: $scope.currentTime, // 用时
            userid: sysUserInfo.getuserinfo().user_ID,  // 用户
            orgid: sysUserInfo.getuserinfo().organization_ID,   // 企业
            knowledgeId: $stateParams.userQuestionsInfo.knowledge.knowledge_Id, //  知识分类
            knowledgeName: $stateParams.userQuestionsInfo.knowledge.knowledge_Name, // 分类名称
            answerXid: $stateParams.xid,    // 类型id
            qualifiedType: $stateParams.stuQueList.passtype ? $stateParams.stuQueList.passtype : 0, // 合格条件  0 全部答完  1固定时长  2  合格率
            qualifiedCondition: $scope.isNull($stateParams.stuQueList.pass) ? 0 : ($stateParams.stuQueList.passtype == 2 ? (parseInt($stateParams.stuQueList.pass)) : (parseFloat($stateParams.stuQueList.pass) * 60)),     // num
            topid: $stateParams.stuQueList.parentId,    // 顶级id
            totals: $stateParams.stuQueList.parentCount, // 顶级题目数
            arrangeid: $stateParams.stuQueList.arrangeId   //任务id
        }
        if ($scope.isNull($stateParams.smartQueParams)) {   // 判断是否是只能抽题
            //  练习
            $scope.queDataParams.groupRecord = $stateParams.groupIndex;
            // 查询题目列表
            $scope.queInfoParams = {
                knowledgeId: $stateParams.userQuestionsInfo.knowledge.knowledge_Id,
                pageIndex: $stateParams.groupIndex,
                pageSize: $stateParams.groupPath,
                userId: sysUserInfo.getuserinfo().user_ID,
                organizationId: sysUserInfo.getuserinfo().organization_ID,
                typeId: $scope.typeId,
                xid: $stateParams.xid
            }
            // 获取数据
            $scope.getUserQuestionsList();
        } else {
            $scope.queDataParams.groupRecord = "ZN_" + new Date().getTime();
            // 查询随机抽题参数
            $scope.queInfoSmartParams = {
                userId: sysUserInfo.getuserinfo().user_ID,   // 用户id 
                organizationId: sysUserInfo.getuserinfo().organization_ID,   // 企业id
                queType: $stateParams.smartQueParams.queType, // 题目类型
                difficulty: $stateParams.smartQueParams.difficulty,    // 题目难度
                queNum: $stateParams.groupPath, // 题目数量  
                knowledgeId: $stateParams.userQuestionsInfo.knowledge.knowledge_Id
            }
            // 随机抽题
            $scope.getUserSmartQuestionsList();
        }

        //if(typeId == 1)
        // all loading
        $scope.stuQueInfoLoading = false;
        //$scope.completeData();
    }
    // 回答信息提示框
    $scope.completeInfoShow = false;
    // 数据提交
    $scope.completeData = function () {
        if ($scope.stuQueInfoLoading)
            return;
        // 最后一道题可能没有做记录
        $scope.lastToNextQuestions($scope.queObj);
        // 处理记录
        $scope.correctQue = 0;
        var queNum = 0;
        var queListParams = angular.copy($scope.haveQuestionsList);
        if (queListParams.length <= 0) {
            Msg.info('提示', '您还没有答题！');
            return;
        }
        // 关闭计时
        $scope.timerFlag = false;
        $interval.cancel($scope.timer);
        angular.forEach(queListParams, function (data, index) {
            if (data.finalIscorrect) {
                data.finalIscorrect = 0;
                queNum++;
            } else {
                data.finalIscorrect = 1;
            }
            // 用户答案            
            if (data.questionType == 6 || data.questionType == 7) {
                data.userAnswer = $scope.isNull(data.userAnswer) ? "" : data.userAnswer.join('|');
                // 题目答案
                if (data.questionType == 7)
                    data.correctAnswer = $scope.isNull(data.correctAnswer) ? "" : data.correctAnswer.join('|');
            } else {
                data.userAnswer = $scope.isNull(data.userAnswer) ? "" : data.userAnswer.toString();
                // 题目答案
                data.correctAnswer = $scope.isNull(data.correctAnswer) ? "" : data.correctAnswer.toString();
            }
        });
        // 计算正确率
        $scope.correctQue = parseInt(queNum / $scope.queList.length * 100);
        console.log($scope.haveQuestionsList, queListParams);
        $scope.stuQueInfoLoading = true;
        // 参数
        $scope.queDataParams.questionJSON = queListParams;
        // 本场用时
        $scope.queDataParams.answerCostTime = $scope.currentTime;
        // 收藏时直接显示
        if ($scope.typeId == 2) {
            $scope.stuQueInfoLoading = false;
            $scope.completeInfoShow = true;
        } else {
            console.log($scope.queDataParams);
            // 非收藏时进行请求
            ST.saveQuestion($scope.queDataParams).then(function (response) {
                $scope.stuQueInfoLoading = false;
                if (response.errorcode == 0) {
                    $scope.completeInfoShow = true;
                    var qian = $scope.typeId == 1 ? "cuoti_" : "";
                    if (!$scope.isNull($stateParams.smartQueParams)) {   // 判断是否是只能抽题
                        qian = 'zn_';
                    }
                    LS.delLS(qian + sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.userQuestionsInfo.knowledge.knowledge_Id + '_' + $stateParams.xid + '_' + $stateParams.groupIndex);
                } else {
                    Msg.error('数据提交失败');
                }
            });
        }
    }
    // 再来一次
    $scope.againQue = function () {
        $state.go("home.stuqueinfo", {}, { reload: true });
    }
    // 下一组
    $scope.nextQueGroup = function (flag) {
        $stateParams.groupIndex = flag;
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_stuQueInfo', $stateParams);
        $state.go("home.stuqueinfo", {}, { reload: true });
    }
    // 关闭
    $scope.closeQue = function () {
        //$stateParams.stuQueList.typeId =0;
        $state.go('home.stuquelist', $stateParams.stuQueList);
    }
    // 错题、收藏 0 练习 1错题 2收藏
    $scope.collError = function (flag) {
        // 默认是练习列表
        $stateParams.stuQueList.typeId = $scope.isNull(flag) ? 0 : flag;
        $state.go('home.stuquelist', $stateParams.stuQueList);
    }
    // 获取题目的信息
    $scope.getUserQuestionsList = function () {
        $scope.stuQueInfoLoading = true;
        ST.findQuestionsPage($scope.queInfoParams).then(function (response) {
            $scope.stuQueInfoLoading = false;
            if (response.errorcode == 0) {
                // 题目List 
                $scope.queList = response.datas;
                $scope.handQueList();
            } else {
                Msg.error('错误', '获取用户题目失败!');
            }
        });
    }
    // 获取随机题目的信息
    $scope.getUserSmartQuestionsList = function () {
        $scope.stuQueInfoLoading = true;
        ST.randomQuestions($scope.queInfoSmartParams).then(function (response) {
            $scope.stuQueInfoLoading = false;
            if (response.errorcode == 0) {
                // 题目List 
                $scope.queList = response.datas;
                $scope.handQueList();
            } else {
                Msg.error('错误', '获取用户题目失败!');
            }
        });

    }
    // 各种类型的返回数据的处理
    $scope.handQueList = function () {
        // 解析JSON
        angular.forEach($scope.queList, function (data, index) {
            // 空值判断
            if (!$scope.isNull(data)) {
                data.questions_Json = JSON.parse(data.questions_Json);
                // 解析B型题  综合题的题目详细
                if (data.questions_Type == 6 || data.questions_Type == 7) {
                    data.questions_Json.answerAnalysis = JSON.parse(data.questions_Json.answerAnalysis);
                    // B型题 小题详细
                    if (data.questions_Type == 6 || data.questions_Type == 7) {
                        angular.forEach(data.questions_Json.answerAnalysis, function (fdata, index) {
                            if (typeof (fdata.questions_Json) == "string") {
                                fdata.questions_Json = JSON.parse(fdata.questions_Json)
                            }
                            if (data.questions_Type == 6) {
                                data.question_name = data.question_name.split('答')[0];
                                data.question_namelist = data.question_name.split(" ");
                            }
                        });
                    }
                }
                // 处理填空题
                if (data.questions_Type == 5) {
                    data.questions_Json.answer = data.questions_Json.answer.split('///');
                }

            } else {
                // 删除空值
                $scope.queList.splice(index, 1);
            }
        });
        //  非收藏时再进行缓存读取
        if ($scope.typeId != 2) {
            // 处理缓存数据
            $scope.handResData();
        }
        if ($scope.queList.length <= 0) {
            Msg.info('提示', '没有发现题目');
            return;
        }
        //从上次答题的地方开始
        var answerIndex = -1;
        var qian = $scope.typeId == 1 ? "cuoti_" : "";
        if (!$scope.isNull($stateParams.smartQueParams)) {   // 判断是否是只能抽题
            qian = 'zn_';
        }
        //获取缓存里答题记录
        var cacheData = LS.getLS(qian + sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.userQuestionsInfo.knowledge.knowledge_Id + '_' + $stateParams.xid + '_' + $stateParams.groupIndex);
        var cacheList = $scope.isNull(cacheData) ? [] : cacheData;
        //遍历开始的索引
        if (cacheList != null && cacheList.length > 0) {
            var id = cacheList[cacheList.length - 1].questionId;
            angular.forEach($scope.queList, function (data, index) {
                if (data.questions_Id == id) {
                    answerIndex = index;
                }
            });
        }
        if (answerIndex == -1) {
            answerIndex = 0;
        }
        // 绑定第一个题目
        $scope.queObj = $scope.queList[answerIndex];
        $scope.queObj.index = answerIndex + 1;
    }
    // 处理本地缓存的数据
    $scope.handResData = function () {
        var qian = $scope.typeId == 1 ? "cuoti_" : "";
        if (!$scope.isNull($stateParams.smartQueParams)) {   // 判断是否是只能抽题
            qian = 'zn_';
        }
        var cacheData = LS.getLS(qian + sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.userQuestionsInfo.knowledge.knowledge_Id + '_' + $stateParams.xid + '_' + $stateParams.groupIndex);
        $scope.haveQuestionsList = $scope.isNull(cacheData) ? [] : cacheData;
        angular.forEach(cacheData, function (data, index) {
            angular.forEach($scope.queList, function (newData, newIndex) {
                if (data.questionId == newData.questions_Id) {
                    // 综合题 B型题 子题赋值答案
                    if (data.questionType == 6 || data.questionType == 7) {
                        angular.forEach(newData.questions_Json.answerAnalysis, function (chilData, index) {
                            chilData.stuAnswer = data.userAnswer[index];
                        })
                    }
                    console.log(data, newData);
                    // 用户答案                    
                    newData.stuAnswer = data.userAnswer;
                    // 回答的是否正确
                    //newData.isCorrect = data.finalIscorrect;
                    $scope.lastToNextQuestions(newData);
                }
            });
        });
    }
    // 保存答案
    $scope.saveQuestionsAnswer = function (queObj, answer, index) {
        // 判空
        if ($scope.isNull(queObj)) {
            console.log('题目为空');
        }
        // 判断有没有答过
        if (queObj.hasOwnProperty('isCorrect') && $scope.questionsIsOpen) {
            Msg.info('提示', '此题目已经答过了！');
        } else {
            switch (parseInt(queObj.questions_Type)) {
                case 1: // 单选题                   
                case 3: // 判断题                    
                case 4: // 问答题 可以在页面禁用                   
                case 6: // B型题
                    queObj.stuAnswer = answer;
                    break;
                case 2: // 多选题                    
                case 5: // 填空题 可以在页面禁用
                    // 如果索引是空那么都放入到第一道题目当中
                    index = $scope.isNull(index) ? 0 : index;
                    // 空的时候创建一个
                    queObj.stuAnswer = $scope.isNull(queObj.stuAnswer) ? [] : queObj.stuAnswer;
                    queObj.stuAnswer[index] = $scope.isNull(queObj.stuAnswer[index]) ? answer : null;
                    break;
            }
        }
    }

    // 比较正确答案
    $scope.compareAnswer = function (item) {
        var flag = false;
        switch (parseInt(item.questions_Type)) {
            case 1: // 单选
                if (item.questions_Json.answer.toUpperCase() == item.stuAnswer.toUpperCase()) {
                    flag = true;
                }
                item.compareAnswer = item.stuAnswer.toUpperCase();
                break;
            case 2: // 多选
                item.compareAnswer = "";
                angular.forEach(item.stuAnswer, function (data, index) {
                    if (!$scope.isNull(data)) {
                        item.compareAnswer += data.toUpperCase();
                    }
                });
                if (item.questions_Json.answer.replace('undefined', '').toUpperCase() == item.compareAnswer.toUpperCase()) {
                    flag = true;
                }
                break;
            case 3: // 判断
                // 用于展示的
                item.compareAnswer = item.stuAnswer;
                if (item.questions_Json.answer == item.compareAnswer) {
                    flag = true;
                }
                break;
            case 4: // 问答
                item.compareAnswer = item.stuAnswer;
                break;
            case 5: // 填空
                item.compareAnswer = item.stuAnswer.join(",");
                if (item.questions_Json.answer.join(",") == item.compareAnswer) {
                    flag = true
                }
                break;
            case 6: // B型题
                if (item.questions_Json.answer.toUpperCase() == item.stuAnswer.toUpperCase()) {
                    flag = true;
                }
                item.compareAnswer = item.stuAnswer.toUpperCase();
                break;

        }
        return flag;
    }

    // 查看答案
    $scope.openAnswer = function (queObj, pObj, flag) {
        if ($scope.isNull(queObj.stuAnswer)) {
            Msg.info('提示', '请作答完');
            return;
        }
        // 不管什么情况都不能再答题
        $scope.questionsIsOpen = true;
        // 是否正确
        queObj.isCorrect = $scope.compareAnswer(queObj);
        queObj.openAnswer = !queObj.openAnswer;

        // B 型题 综合题的总答案是否正确
        if (!$scope.isNull(pObj) && flag == 6) {
            var queCorrect = true;
            // 遍历所有题有没有答对
            angular.forEach(pObj.questions_Json.answerAnalysis, function (data, index) {
                if (queCorrect) { // 默认true  只要有一个为false 的则失败
                    queCorrect = data.isCorrect;
                }
            });
            // 赋值给最大的对象
            pObj.isCorrect = queCorrect;

        }
        if (queObj.openAnswer) { // 加入答题记录 -- 计算题目的答题情况

            if (flag == 6) {
                $scope.lastToNextQuestions(pObj)
            } else {

                $scope.lastToNextQuestions(queObj);
            }
        }
        console.log(queObj);
    }

    // 选中某道题
    $scope.selectedQue = function (item, index) {
        // 判断 当前题目存不存在
        if (!$scope.isNull($scope.queObj)) {
            // 处理一下当前题目的情况
            $scope.lastToNextQuestions($scope.queList[$scope.queObj.index - 1]);

        }
        // 绑定当前题目
        $scope.queObj = item;
        // 当前题目的索引
        $scope.queObj.index = index;
    }
    // 下一题/上一题   默认index 是下一个数组的 index true上一题  false下一题
    $scope.nextQue = function (queObj, flag) {
        // 如果开启的情况下那么可以随便答题
        if ($scope.userQuestionsInfo.isOpen) {
            $scope.questionsIsOpen = false;
            queObj.openAnswer = false;
        }
        var newIndex = queObj.index;
        // 处理一下当前的题
        $scope.lastToNextQuestions(queObj);
        // 判断切换上一题还是下一题
        if (flag) {   // 上一题
            $scope.queObj = $scope.queList[queObj.index - 2];
            $scope.queObj.index = newIndex - 1;
        } else {
            $scope.queObj = $scope.queList[queObj.index];
            $scope.queObj.index = newIndex + 1;
        }
        if ($scope.queObj.stuAnswer == undefined || $scope.queObj.stuAnswer.length <= 0) {
            $scope.queObj.stuAnswer = [];
        }
    }
    // 处理 上一题 下一题操作之前的答案信息
    $scope.lastToNextQuestions = function (queObj) {

        if (parseInt(queObj.questions_Type) != 6 && parseInt(queObj.questions_Type) != 7) {
            // 必须作答不然不算记录
            if (!$scope.isNull(queObj.stuAnswer)) {
                queObj.isCorrect = $scope.compareAnswer(queObj);
                // 插入已答题目中
                $scope.calHaveQuestionsNum(queObj);
            }
        } else {    // B型题 或者 综合题
            // 最终的答题情况
            var queCorrect = true;
            // 有没有作答
            var isExists = false;
            // 外层信息
            queObj.stuAnswer = [];
            angular.forEach(queObj.questions_Json.answerAnalysis, function (data, index) {
                // 必须作答不然不算记录                
                if (!$scope.isNull(data.stuAnswer)) {
                    // 存入最外层信息
                    queObj.stuAnswer.push(data.stuAnswer);
                    isExists = true;
                    // 判断子题是否正确
                    data.isCorrect = $scope.compareAnswer(data);
                    if (queCorrect) { // 默认true  只要有一个为false 的则失败
                        queCorrect = data.isCorrect;
                    }
                } else {
                    //  这个是空值                  
                    queCorrect = data.isCorrect;
                    // 题目没有答赋值空
                    queObj.stuAnswer.push(null);

                }
            });
            // 如果有作答那么再记录答题结果
            if (isExists) {
                queObj.isCorrect = queCorrect;
                // 插入已答题目中
                $scope.calHaveQuestionsNum(queObj);
            }
        }
    }
    // 计算已答题目数 正确率 等等 提交数据的存储
    $scope.calHaveQuestionsNum = function (queObj) {
        // 默认可以添加
        var isExists = true;

        // 去除重复
        angular.forEach($scope.haveQuestionsNum, function (data, index) {
            if (data == queObj.questions_Id)
                isExists = false;
        });
        // 添加
        if (isExists) {
            $scope.haveQuestionsNum.push(queObj.questions_Id);
        }
        // 添加题目 比较题目存不存在
        $scope.handQuestions(queObj);


    }
    // 处理本地答题记录
    $scope.handQuestions = function (queObj) {
        // 记录赋值
        var isExists = -1;
        angular.forEach($scope.haveQuestionsList, function (data, index) {
            if (data.questionId == queObj.questions_Id) {
                isExists = index;
                //data = queObj;
            }
        });
        var queNewObj = {
            //  题目id
            questionId: queObj.questions_Id,
            // 题目类型
            questionType: queObj.questions_Type,
            // 用户答案
            userAnswer: queObj.stuAnswer,
            // 题目答案
            correctAnswer: queObj.questions_Json.answer,
            // 答题时长
            recordCostTime: $scope.currentQueTime,
            // 答题是否正确
            finalIscorrect: queObj.isCorrect
        }
        if (isExists != -1) {
            $scope.haveQuestionsList[isExists] = queNewObj;
        } else {
            $scope.haveQuestionsList.push(queNewObj);
        }
        // 答题时长
        $scope.currentQueTime = 0;
        // 收藏时不记录联系记录
        if ($scope.typeId != 2) {
            var qian = $scope.typeId == 1 ? "cuoti_" : "";
            if (!$scope.isNull($stateParams.smartQueParams)) {   // 判断是否是只能抽题
                qian = 'zn_';
            }
            // 存入答题信息
            LS.setLS(qian + sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.userQuestionsInfo.knowledge.knowledge_Id + '_' + $stateParams.xid + '_' + $stateParams.groupIndex, $scope.haveQuestionsList);
            console.log(LS.getLS(sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.userQuestionsInfo.knowledge.knowledge_Id + '_' + $stateParams.xid + '_' + $stateParams.groupIndex));
        }
        // 记录上次答题的组
        if ($scope.typeId != 0) {
            LS.setLS("zu_" + sysUserInfo.getuserinfo().organization_ID + '_' + sysUserInfo.getuserinfo().user_ID + '_' + $stateParams.userQuestionsInfo.knowledge.knowledge_Id + '_' + $stateParams.xid + '_' + $scope.typeId, $stateParams.groupIndex);
        }
    }
    // 收藏题目请求参数
    $scope.collQueParams = {
        userId: sysUserInfo.getuserinfo().user_ID,
        knowledgeId: $stateParams.userQuestionsInfo.knowledge.knowledge_Id,
        questionId: "",
        questionType: "",
        orgid: sysUserInfo.getuserinfo().organization_ID
    }
    // 请求方法 0 收藏 1不收藏
    $scope.postCollQue = function (queObj) {
        if ($scope.stuQueInfoLoading) {
            Msg.info('提示', '正在收藏');
            return;
        }
        $scope.stuQueInfoLoading = true;
        // 赋值题目内容
        $scope.collQueParams.questionId = queObj.questions_Id;
        $scope.collQueParams.questionType = queObj.questions_Type;
        if (queObj.knowledge_Name == 1 && $scope.typeId != 2) {  // 收藏
            ST.collectionQuestion($scope.collQueParams).then(function (response) {
                $scope.stuQueInfoLoading = false;
                if (response.errorcode == 0) {
                    queObj.knowledge_Name = 0;
                } else {
                    Msg.error('错误', '请重新收藏');
                }
            });
        } else {  // 取消收藏
            ST.deleteCollection($scope.collQueParams).then(function (response) {
                $scope.stuQueInfoLoading = false;
                if (response.errorcode == 0) {
                    queObj.knowledge_Name = 1;
                    if ($scope.typeId == 2)
                        Msg.success("成功", "再次进入收藏本题会消失");
                } else {
                    Msg.error('错误', '请重试');
                }
            });
        }

    }
    // 截取字符串
    $scope.substr = function (data, start, end) {
        return data.substr(start, data.indexOf(end));
    }
    // 时间开始暂停
    $scope.timerFlagClick = function () {
        $scope.timerFlag = !$scope.timerFlag;
    }
    // 创建计时器
    $scope.timerFun = function () {
        if ($scope.timer) { // 关闭计时器
            $scope.timer = null
        } else {
            // 计时器
            $scope.timer = $interval(function () {
                if ($scope.timerFlag) {
                    // 总时长(秒)
                    $scope.countTime++;
                    // 当前时长
                    $scope.currentTime++;
                    // 单道题目的时长
                    $scope.currentQueTime++;
                }
            }, 1000);
        }
    }
    $scope.$on('$destroy', function () {
        $interval.cancel($scope.timer);
    });
    $scope.init();

} ])
// 解析时间
.filter('is_colon_time', ['$sce',
function ($sce) {
    return function (text) {
        if (text == undefined || text == null || text == "") {
            return '0:00:00';
        } else {
            var s = text % 60 < 10 ? '0' + (text % 60) : text % 60;
            var m = parseInt(text / 60) < 10 ? '0' + parseInt(text / 60) : parseInt(text / 60);
            var h = parseInt(m / 60);
            return h + ':' + m + ':' + s;
        }
    };
} ])
.filter('is_listtostr', ['$sce',
function ($sce) {
    return function (text) {
        var restext = '空';
        if (text == undefined || text == null || text == "") {
            return restext;
        } else {
            restext = '';
            angular.forEach(text, function (data, index) {
                restext += data + ',';
            });
            restext = restext.substr(0, restext.length - 1);
            return restext;
        }
    };
} ])
//  判断空值
.filter('is_null', ['$sce',
function ($sce) {
    return function (text) {
        if (text == undefined || text == null || text == "" || text.length <= 0) {
            return 0;
        } else {
            return text;
        }
    };
} ]);

